package com.kgc.storeconsumer.controller;


import com.kgc.basic.util.ResponseMsg;
import com.kgc.store.pojo.InStore;
import com.kgc.store.pojo.OutStore;
import com.kgc.storeconsumer.feign.CostAdjustmentFeign;
import com.kgc.storeconsumer.feign.InStoreFeign;
import com.kgc.storeconsumer.feign.OutStoreFeign;
import com.kgc.storeconsumer.feign.OutStoreWorkFlowFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Controller
@CrossOrigin("*")
@RequestMapping("/outStore")
public class OutStoreController {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private OutStoreFeign outStoreFeign;

    @Autowired
    private OutStoreWorkFlowFeign outStoreWorkFlowFeign;

    @RequestMapping("getOutStoreList")
    @ResponseBody
    public ResponseMsg getOutStoreList(@RequestBody Map<String, Object> map){
        logger.info("OutStoreController getOutStoreList map:"+map);
        ResponseMsg msg =outStoreFeign.getOutStoreList(map);
        logger.debug("OutStoreController getOutStoreList msg:"+msg);
        return msg;
    }

    @RequestMapping("delOutStore")
    @ResponseBody
    public ResponseMsg delOutStore(Integer id){
        logger.info("OutStoreController delOutStore id:"+id);
        ResponseMsg msg =outStoreFeign.delOutStore(id);
        logger.debug("OutStoreController delOutStore msg:"+msg);
        return msg;
    }

    @RequestMapping("addOutStore")
    @ResponseBody
    ResponseMsg addOutStore(@RequestBody OutStore outStore){
        logger.info("OutStoreController addOutStore outStore:"+outStore);
        ResponseMsg msg =outStoreFeign.addOutStore(outStore);
        logger.debug("OutStoreController addOutStore msg:"+msg);
        return msg;
    }

    @RequestMapping("getOutStoreByCode")
    @ResponseBody
    ResponseMsg getOutStoreByCode(String code){
        logger.info("OutStoreController getOutStoreByCode code:"+code);
        ResponseMsg msg =outStoreFeign.getOutStoreByCode(code);
        logger.debug("OutStoreController getOutStoreByCode msg:"+msg);
        return msg;
    }

    @RequestMapping("check")
    @ResponseBody
    ResponseMsg check(@RequestBody Map<String,Object> map){
        ResponseMsg responseMsg = new ResponseMsg();
        logger.info("OutStoreController check params,{}",map.toString());
        Map<String,Object> variables = new HashMap<>();
        variables.put("code",(String) map.get("code"));//单据编号
        variables.put("checkManId",(Integer) map.get("checkManId"));//审批人
        variables.put("checkManName",(String) map.get("checkManName"));//审批人
        variables.put("checkComment",(String) map.get("checkComment"));//审批意见
        variables.put("checkDate",new Date());//审批时间
        variables.put("checkRes",(boolean)map.get("checkRes"));//审批结果
        com.kgc.activiti.util.ResponseMsg msg=  outStoreWorkFlowFeign.competeTask(variables);
        responseMsg.setCode(msg.getCode());
        responseMsg.setMsg(msg.getMsg());
        return responseMsg;
    }
}

